home *** CD-ROM | disk | FTP | other *** search
- // HTBDDE.cpp : Defines the initialization routines for the DLL.
- //
-
- /////////////////////////////////////////////////////////////////////////////
- // Includes
- //
- #include "stdafx.h"
- #include "mfcdde.h"
- #include "HTBDDE.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- //
- // Note!
- //
- // If this DLL is dynamically linked against the MFC
- // DLLs, any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- //
- // For example:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // normal function body here
- // }
- //
- // It is very important that this macro appear in each
- // function, prior to any calls into MFC. This means that
- // it must appear as the first statement within the
- // function, even before any object variable declarations
- // as their constructors may generate calls into the MFC
- // DLL.
- //
- // Please see MFC Technical Notes 33 and 58 for additional
- // details.
- //
-
- /////////////////////////////////////////////////////////////////////////////
- // CHtbDdeApp
-
- BEGIN_MESSAGE_MAP(CHtbDdeApp, CWinApp)
- //{{AFX_MSG_MAP(CHtbDdeApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CHtbDdeApp construction
-
- CHtbDdeApp::CHtbDdeApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CHtbDdeApp object
- //
- CHtbDdeApp theApp;
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Defines
- //
- #define DLLEXPORT __declspec( dllexport )
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: CHtbDdeApp::InitInstance
-
- Description:
-
- Return type: BOOL
-
- Notes:
-
- */
- BOOL CHtbDdeApp::InitInstance()
- {
- DdeInitialize();
-
- m_pClient = new CDdeClient;
-
- if (!m_pClient)
- {
- return FALSE;
- }
- else
- {
- return CWinApp::InitInstance();
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: CHtbDdeApp::ExitInstance
-
- Description:
-
- Return type: int
-
- Notes:
-
- */
- int CHtbDdeApp::ExitInstance()
- {
- if (m_pClient)
- {
- delete m_pClient;
- }
-
- DdeCleanUp();
-
- return CWinApp::ExitInstance();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Exported Functions
- //
-
- extern "C"
- {
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Ddeconnect
-
- Description: Initiate a DDE conversation with a DDE Server
-
- Return type: DWORD handle to the active DDE conversation
- or 0 if an error occurred
- Argument: char * szApplication DDE application - see your app specific
- documenation
- Argument: char * szTopic DDE topic - see your app specific
- documenation
-
- Notes:
-
- */
- DLLEXPORT DWORD Ddeconnect(char * szApplication, char * szTopic)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->MakeConnection("", szApplication, szTopic);
-
- if (!pConnection)
- {
- return 0L;
- }
-
- return (DWORD)pConnection->m_hConv;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Ddeterminate
-
- Description: Terminate a DDE conversation
-
- Return type: short
- Argument: DWORD hConv handle to the DDE conversation
-
- Notes:
-
- */
- DLLEXPORT short Ddeterminate(DWORD hConv)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
-
- if (!pConnection)
- {
- return (short)FALSE;
- }
-
- return (short)pConnection->Disconnect();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Ddetimout
-
- Description: Set the DDE timeout for this conversation
-
- Return type: DWORD returns the previous timeout value
- Argument: DWORD hConv handle to the DDE conversation
- Argument: DWORD nTimeOut the new timeout value
-
- Notes:
-
- */
- DLLEXPORT DWORD Ddetimeout(DWORD hConv, DWORD nTimeOut)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
-
- if (!pConnection)
- {
- return DEFAULT_TIMEOUT;
- }
-
- return pConnection->SetTimeOut(nTimeOut);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Ddeexecute
-
- Description: Execute a specific command using an existing DDE conversation
-
- Return type: short
- Argument: DWORD hConv handle to the DDE conversation
- Argument: char * szCommand
-
- Notes:
-
- */
- DLLEXPORT short Ddeexecute(DWORD hConv, char * szCommand)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
-
- if (!pConnection)
- {
- return (short)FALSE;
- }
-
- return (short)pConnection->Execute(szCommand);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Dderequest
-
- Description: Request information from a DDE Server
-
- Return type: char *
- Argument: DWORD hConv handle to the DDE conversation
- Argument: char * szItem
-
- Notes:
-
- This impementation allows a char * return only.
-
- */
- DLLEXPORT char * Dderequest(DWORD hConv, char * szItem)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- int nSize;
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
-
- if (!pConnection)
- {
- return "";
- }
-
- return pConnection->Request(szItem, &nSize);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Ddepoke
-
- Description: Perform a DDE Poke
-
- Return type: short
- Argument: DWORD hConv handle to the DDE conversation
- Argument: char * szItem
- Argument: char * szData
-
- Notes:
-
- */
- DLLEXPORT short Ddepoke(DWORD hConv, char * szItem, char * szData)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CDdeConnection *pConnection;
-
- pConnection = theApp.m_pClient->FindConnection((HCONV)*(DWORD *)hConv);
-
- if (!pConnection)
- {
- return (short)FALSE;
- }
-
- return (short)pConnection->Poke(szItem, szData, strlen(szData));
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: Runexe
-
- Description: Run a windows program
-
- Return type: short
- Argument: char *szExecutable
- Argument: short nCmdShow
-
- Notes:
-
- */
- DLLEXPORT short Runexe(char *szExecutable, short nCmdShow)
- {
- return (short)WinExec((const char *)szExecutable, nCmdShow);
- }
-
- } // extern "C"